package com.i2bt.app.transmission;

import com.i2bt.R;
import com.i2bt.adapter.ListAdapter;
import com.i2bt.app.BaseFragment;
import com.i2bt.app.transmission.model.TransmissionGroup;
import com.i2bt.app.transmission.model.Transmission_item;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ExpandableListView;

import java.util.ArrayList;
import java.util.List;

public class TransmissionFragment extends BaseFragment implements
		ExpandableListView.OnChildClickListener, OnItemLongClickListener {
	private List<TransmissionGroup> group;
	private List<Transmission_item> downloadgroup, uploadgroup;
	ListAdapter adapter;
	ExpandableListView ex;

	public TransmissionFragment() {
		downloadgroup = new ArrayList<Transmission_item>();
		uploadgroup = new ArrayList<Transmission_item>();
		TransmissionGroup dl = new TransmissionGroup("下载", downloadgroup);
		TransmissionGroup ul = new TransmissionGroup("上传", uploadgroup);
		group = new ArrayList<TransmissionGroup>();
		group.add(dl);
		group.add(ul);
		System.out.println("初始化下载数据");
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fragment_tra, container, false);
	}

	@Override
	public void onPrepareOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		super.onPrepareOptionsMenu(menu);
		System.out.println("创建kkk");
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		initView();
	}

	@Override
	protected void initView() {
		adapter = new ListAdapter(context, group);
		ex = (ExpandableListView) activity.findViewById(R.id.listView);
		ex.setOnChildClickListener(this);
		ex.setOnItemLongClickListener(this);
		ex.setAdapter(adapter);
		ex.expandGroup(0);
		ex.expandGroup(1);
	}

	public void addDownLoadItem(Transmission_item item) {
		downloadgroup.add(item);
	}

	public void addUploadItem(Transmission_item item) {
		uploadgroup.add(item);
	}

	public void addDownload(int drawableId, String filename, String Info,
			String path) {
	}

	public void addUploadload(int drawableId, String filename, String Info,
			String path) {
	}

	public int getCompleteSize(int group, int position) {
		return this.getItem(group, position).getCompleteSize();
	}

	public int getCompleteRate(int group, int position) {
		return this.getItem(group, position).getCompleteRate();
	}

	public int getDownloadItemCount() {
		return downloadgroup.size();
	}

	public int getUploadItemCount() {
		return uploadgroup.size();

	}

	public void setCompleteSize(int group, int position, int completeSize) {
		this.getItem(group, position).setCompleteSize(completeSize);
	}

	public Transmission_item getItem(int group, int position) {
		if (group == 0) {
			return downloadgroup.get(position);
		} else if (group == 1) {
			return uploadgroup.get(position);
		}
		return null;
	}

	@Override
	public boolean onChildClick(ExpandableListView parent, View v,
			int groupPosition, int childPosition, long id) {
		// TODO Auto-generated method stub
		System.out.println("点击子项");
		return false;
	}

	@Override
	public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,
			long arg3) {
		// TODO Auto-generated method stub
		System.out.println("长按子项");
		return false;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
	}

	@Override
	protected void logic() {
		// TODO Auto-generated method stub

	}

	@Override
	public void backHomeOperate() {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean onKeyBack() {
		// TODO Auto-generated method stub
		return false;
	}

	public void setProgress(int i, int i2, int j) {
		// TODO Auto-generated method stub
		
	}

}
